package com.apes.scm.masterdata.frame.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 功能：组织信息 定义
 *
 * @author HuJianlin
 * @create 2018-03-07 15:31
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = "mas_org")
public class Organization extends Model {

    @Id
    @Column(name = "id")
    @Comment("编码组织")
    private String id;  //编码组织

    @Name
    @Column(name = "name", nullable = false, length = 120)
    @Comment("组织名称")
    private String name; //组织名称

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("所属公司")
    private PartyRole company; //所属公司)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "org_type", referencedColumnName = "id")
    @Comment("组织类型")
    private Enumeration orgType; //组织类型（businessClass）（BC_purchase：采购组织; BC_sale：销售组织; BC_other：其他）

    @Column(name = "ORIGIN", length = 20)
    @Comment("外部ID")
    private String origin; //外部ID

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效")
    private boolean valid = true; //有效

}
